home *** CD-ROM | disk | FTP | other *** search
- /*
- * DemoApp.c
- * Copyright © 1992-93 Apple Computer Inc. All rights reserved.
- * This sub-class to CEditApp adds Digital Signature
- * capabilities to the sample editor.
- */
- #include "DemoApp.h"
- #include "DemoEditDoc.h"
- #include "DemoSignedObject.h"
- #include "DemoSignedObjectDialog.h"
- #include <Commands.h>
- #include <CBartender.h>
- #include <CList.h>
- #include <Global.h>
- #include <Exceptions.h>
- #include <Errors.h>
- extern CApplication *gApplication;
- extern CBartender *gBartender;
- extern CursHandle gWatchCursor;
- extern CBureaucrat *gGopher;
- extern OSType gSignature;
- Boolean gHasDigitalSignatureManager;
-
- OSErr SystemSupportsAOCE(void);
- void Message(
- const StringPtr textString
- );
-
- /*
- * IDemoApp
- * Just call the CEditApp initializer.
- */
- void
- DemoApp::IDemoApp(void)
- {
- gHasDigitalSignatureManager = (SystemSupportsAOCE() == noErr);
- CEditApp::IEditApp();
- if (gHasDigitalSignatureManager == FALSE) {
- Message(
- "\pYour system does not support the Digital Signature"
- " Manager. Some menu items have been disabled for"
- " your convenience."
- );
- }
- itsDemoSignedObject = new (DemoSignedObject);
- itsDemoSignedObject->IDemoSignedObject();
- }
-
- void
- DemoApp::SetUpFileParameters(void)
- {
- inherited::SetUpFileParameters();
- sfNumTypes = 2;
- sfFileTypes[0] = 'TEXT';
- sfFileTypes[1] = 'ttro'; /* TeachText read-only */
- gSignature = 'ttxt'; /* TeachText */
- }
-
-
- /*
- * This is called by a patch to ExitToShell whenever the application
- * exits, even if it dies a horrible death. This ensures that the
- * Digital Signature Manager's context is cleared. If we don't do
- * this, the application will fail when it is restarted.
- */
- void
- DemoApp::RemovePatches(void)
- {
- DisposeSignerContext();
- inherited::RemovePatches();
- }
-
- /*
- * SetUpMenus
- * Our special menus have already been added to the
- * resource file. Just call CEditDoc's method.
- */
- void
- DemoApp::SetUpMenus(void)
- {
- inherited::SetUpMenus();
- }
-
- /*
- * DoCommand
- * Process our special commands. OpenSignedFile was added
- * to the File Menu by the SetUpMenus method.
- * Note that we have to override the "new document" method
- * in order to create a signable document.
- */
- void
- DemoApp::DoCommand(
- long theCommand
- )
- {
- SFReply macSFReply;
-
- switch (theCommand) {
- case cmdDebugTrapOnError:
- /*
- * Enable/disable a Debug trap if an
- * error is detected. This might reasonably
- * be enabled if you are running under the
- * Think C debugger.
- */
- gBreakFailure = !(gBreakFailure);
- gBartender->CheckMarkCmd(
- cmdDebugTrapOnError,
- gBreakFailure
- );
- break;
- case cmdOpenSignedFile:
- ChooseFile(&macSFReply);
- if (macSFReply.good) {
- SetCursor(*gWatchCursor);
- OpenSignedDocument(&macSFReply);
- }
- break;
- case cmdPrint:
- inherited::DoCommand(theCommand);
- break;
- case cmdOpen:
- /*
- * We override cmdOpen here to detect the "trying to open
- * a read-only file" error that occurs if the user tries
- * to open a signed file using File/Open.
- */
- TRY {
- inherited::DoCommand(theCommand);
- }
- CATCH {
- if (gLastError == afpAccessDenied) {
- Message(
- "\pThis file was set “locked” (i.e.,"
- " read-only) by the Finder or by signing"
- " the file. If it was signed, you can use"
- " Open and Verify File to open it read-only."
- );
- gApplication->JumpToEventLoop();
- }
- }
- ENDTRY;
- break;
- case cmdNew:
- SetCursor(*gWatchCursor);
- CreateSignedDocument();
- break;
- case cmdSignedObjectDemo:
- /*
- * The user chose "Signed Object Demo."
- * -- we treat this as a modal dialog, even though
- * there's no real reason to. itsDemoSignedObjectDialog
- * is in the application object instance so it is
- * globalized for debugging: it could just as well
- * be a local variable as it has no existance outside
- * of this code sequence.
- */
- itsDemoSignedObjectDialog = new (DemoSignedObjectDialog);
- TRY {
- itsDemoSignedObjectDialog->IDemoSignedObjectDialog(
- this,
- itsDemoSignedObject
- );
- itsDemoSignedObjectDialog->DoModalDialog(cmdOK);
- }
- CATCH {
- ForgetObject(itsDemoSignedObjectDialog);
- }
- ENDTRY;
- ForgetObject(itsDemoSignedObjectDialog);
- break;
- case cmdAbout:
- if (gHasDigitalSignatureManager) {
- Message(
- "\pDigital Signature Sample."
- " Copyright © 1993 Apple Computer Inc."
- " All Rights Reserved."
- );
- }
- else {
- Message(
- "\pDigital Signature Sample."
- " Copyright © 1993 Apple Computer Inc."
- " All Rights Reserved."
- " Note: this system does not support"
- " the Digital Signature Manager."
- );
- }
- break;
- default:
- inherited::DoCommand(theCommand);
- break;
- }
- }
-
- /*
- * UpdateMenus
- */
- void
- DemoApp::UpdateMenus(void)
- {
- inherited::UpdateMenus(); /* Enable standard commands */
- /*
- * Allow opening existing (unsigned) text files,
- * and allow opening (with verification) of signed text files.
- */
- gBartender->EnableCmd(cmdOpen);
- gBartender->DisableCmd(cmdRevert);
- gBartender->EnableMenu(MENU_ObjectDemo);
- gBartender->EnableCmd(cmdSignedObjectDemo);
- gBartender->EnableCmd(cmdDebugTrapOnError);
- /*
- * If we have the Digital Signature Manager and there is a
- * document attached, enable the "Close and Sign File" menu item.
- */
- if (gHasDigitalSignatureManager) {
- gBartender->EnableCmd(cmdOpenSignedFile);
- if (itsDirectors != NULL
- && itsDirectors->GetNumItems() > 0)
- gBartender->EnableCmd(cmdCloseAndSignFile);
- }
- }
-
- /*
- * Override CEditApp::OpenDocument to enable the "save,
- * close, and sign" menu option.
- */
- void
- DemoApp::OpenDocument(
- SFReply *macSFReply
- )
- {
- DemoEditDoc *theDocument = NULL;
-
- TRY {
- theDocument = new(DemoEditDoc);
- theDocument->IDemoEditDoc(this, TRUE);
- theDocument->OpenFile(macSFReply);
- }
- CATCH {
- ForgetObject( theDocument);
- }
- ENDTRY;
- }
- /*
- * OpenSignedDocument
- * This is called when the user chooses Open and Verify Document
- * from the file menu.
- */
- void
- DemoApp::OpenSignedDocument(
- SFReply *macSFReply
- )
- {
- DemoEditDoc *theDocument = NULL;
-
- TRY {
- theDocument = new(DemoEditDoc);
- theDocument->IDemoEditDoc(this, TRUE);
- theDocument->OpenAndVerifyFile(macSFReply);
- }
- CATCH {
- ForgetObject(theDocument);
- }
- ENDTRY;
- }
-
- /*
- * CreateSignedDocument
- * This is called when the user chooses New from the
- * file menu. It is identical to CreateDocument in
- * CEditApp, except that it creates a signable document.
- */
- void
- DemoApp::CreateSignedDocument(void)
- {
- DemoEditDoc *theDocument = NULL;
-
- TRY {
- theDocument = new(DemoEditDoc);
- theDocument->IDemoEditDoc(this, TRUE);
- theDocument->NewFile();
- }
- CATCH {
- ForgetObject(theDocument);
- }
- ENDTRY;
- }
-
-
-